class Page4 extends egret.Sprite{
	private building:egret.Bitmap;
	private blink:egret.Bitmap;
	private arr_pic;
	private bg1:egret.Bitmap;
	private bg2:egret.Bitmap;

	private BDL:egret.Bitmap;
	private BDR:egret.Bitmap;

	private BDLLight:egret.Bitmap;
	private BDRLight:egret.Bitmap;

	private water:egret.MovieClip;
	public constructor() {
		super();
		this.initial();
	}
	public initial(){
		this.bg1=new egret.Bitmap(RES.getRes("bg44_png"));
		this.addChild(this.bg1);
		this.bg1.x=740/2;this.bg1.y=1136/2;
		this.bg1.anchorOffsetX=this.bg1.width/2;this.bg1.anchorOffsetY=this.bg1.height/2;
		this.bg2=new egret.Bitmap(RES.getRes("bg4_png"));
		
		this.bg2.anchorOffsetX=this.bg2.width/2;this.bg2.anchorOffsetY=this.bg2.height/2;
		// this.addChild(this.bg2);

		var data=RES.getRes("water_json");
        var txtr=RES.getRes("water_png");
        var mcFactory=new egret.MovieClipDataFactory(data,txtr);
        this.water=new egret.MovieClip(mcFactory.generateMovieClipData("water"));
		this.addChild(this.water);
		this.water.gotoAndPlay("water",-1);
		this.water.anchorOffsetX=this.water.width/2;this.water.anchorOffsetY=this.water.height/2;


		this.BDL=new egret.Bitmap(RES.getRes("BDL_png"));
		this.addChild(this.BDL);

		this.BDR=new egret.Bitmap(RES.getRes("BDR_png"));
		this.addChild(this.BDR);

		this.BDLLight=new egret.Bitmap(RES.getRes("BDLL_png"));
		this.addChild(this.BDLLight);
		this.BDLLight.x=112;this.BDLLight.y=668;

		this.BDRLight=new egret.Bitmap(RES.getRes("BDRL_png"));
		this.addChild(this.BDRLight);
		this.BDRLight.x=606;this.BDRLight.y=415;


		this.arr_pic=new Array();
		for(var z=1;z<=5;z++){
			var pic=new egret.Bitmap(RES.getRes("page4pic"+z+"_png"));
			this.addChild(pic);
			switch(z){
				case 1:pic.x=175+pic.width/2;pic.y=131+pic.height/2;pic.anchorOffsetX=pic.width/2;pic.anchorOffsetY=pic.height/2;break;
				case 2:pic.x=135;pic.y=333;break;
				case 3:pic.x=205;pic.y=403;break;
				case 4:pic.x=236;pic.y=460;break;
				case 5:pic.x=263;pic.y=552;break;
			}
			this.arr_pic.push(pic);
		}
		this.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.TB,this);

	}
	private TB(e:TouchEvent){
		this.touchEnabled=false;
		GoEvent.msg.dispatchEvent(new GoEvent("ChangePage","5"));
	}
	public End(){
		egret.Tween.get(this).to({alpha:0},600,egret.Ease.cubicOut);
	}

	public Show(){
		var This=this;
		setTimeout(function(){
			This.touchEnabled=true;
		},4000)


		var This=this;
		this.alpha=0;
		egret.Tween.get(this).to({alpha:1},700,egret.Ease.cubicOut);
		this.bg1.alpha=0;this.bg1.scaleX=2,this.bg1.scaleY=2;
		egret.Tween.get(this.bg1).to({alpha:1,scaleX:1,scaleY:1},800,egret.Ease.cubicOut);
		this.bg2.x=740/2;this.bg2.y=737+this.bg2.height/2+500;
		this.bg2.alpha=0;this.bg2.scaleX=1.8,this.bg2.scaleY=1.8;
		egret.Tween.get(this.bg2).wait(500).to({alpha:1,scaleX:1,scaleY:1,y:737+this.bg2.height/2},1200,egret.Ease.cubicOut);


		this.water.x=740/2;this.water.y=737+this.water.height/2+500;
		this.water.scaleX=1.8,this.water.scaleY=1.8;
		egret.Tween.get(this.water).wait(500).to({scaleX:1,scaleY:1,y:737+this.water.height/2},1200,egret.Ease.cubicOut);



		this.BDL.scaleX=1.5;this.BDL.scaleY=1.5;
		this.BDR.scaleX=1.5;this.BDR.scaleY=1.5;

		this.BDL.x=-this.BDL.width*1.5;
		this.BDR.x=623+this.BDR.width*1.5;

		this.BDL.y=198;
		this.BDR.y=303;
		egret.Tween.get(this.BDL).wait(900).to({x:0,scaleX:1,scaleY:1},1000,egret.Ease.cubicOut);
		egret.Tween.get(this.BDR).wait(900).to({x:623,scaleX:1,scaleY:1},1000,egret.Ease.cubicOut);

		this.BDLLight.alpha=0;this.BDRLight.alpha=0;
		setTimeout(function(){
			
			egret.Tween.get(This.BDLLight,{loop:true}).to({alpha:0.6},1000,egret.Ease.cubicOut).to({alpha:1},700,egret.Ease.cubicOut)
			egret.Tween.get(This.BDRLight,{loop:true}).to({alpha:0.6},1000,egret.Ease.cubicOut).to({alpha:1},700,egret.Ease.cubicOut)
		},2800);
		egret.Tween.get(This.BDLLight).wait(1700).to({alpha:1},1000,egret.Ease.cubicOut)
		egret.Tween.get(This.BDRLight).wait(1700).to({alpha:1},1000,egret.Ease.cubicOut)
		
		
		for(var z=0;z<this.arr_pic.length;z++){
			this.arr_pic[z].alpha=0;
			this.arr_pic[z].y+=50;
			if(z==0){
				this.arr_pic[z].y=131+this.arr_pic[z].height/2
				this.arr_pic[z].scaleX=2;this.arr_pic[z].scaleY=2;
				egret.Tween.get(this.arr_pic[z]).wait(1200+z*500-z*50).to({alpha:1,scaleX:1,scaleY:1},800,egret.Ease.cubicOut);
			}
			else if(z==1){
				this.arr_pic[z].y=333;

				this.arr_pic[z].x=135-30;
				egret.Tween.get(this.arr_pic[z]).wait(1200+z*500-z*50).to({alpha:1,x:135},800,egret.Ease.cubicOut);
		
			}
			else{
			egret.Tween.get(this.arr_pic[z]).wait(1200+z*500-z*50).to({alpha:1,y:this.arr_pic[z].y-50},800,egret.Ease.cubicOut);
			}
		}
	}
}